package com.lyrpx.mapper;

import com.lyrpx.pojo.Person;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

public interface PersonMapper {
    /*按id查询表中该人员的身份信息*/
    @Select("select a.*,b.id cardId,b.code from tb_person a " +
            "join tb_idcard b " +
            "on a.card_id=b.id " +
            "where a.id=#{id}")
    @Results({@Result(property = "id", column = "id",id = true),
            @Result(property = "name", column = "name"),
            @Result(property = "age", column = "age"),
            @Result(property = "sex", column = "sex"),
            @Result(property = "card.id", column = "cardId"),
            @Result(property = "card.code", column = "code")
    })
    Person findCodeById(int id);
    /*按id查询t_person表中该人员的身份信息*/
    @Select("select * from tb_person where id=#{id}")
    @Results(value = {@Result(property = "id", column = "id", id = true),
            @Result(property = "name", column = "name"),
            @Result(property = "age", column = "age"),
            @Result(property = "sex", column = "sex"),
            @Result(property = "card", column = "card_id",
                    one = @One(select = "com.lyrpx.mapper.IdCardMapper.selectIdCardById"))
    })
    Person selectPersonById(int id);
}
